package com.zh.push.jpush;

import cn.jpush.api.push.model.Message;
import cn.jpush.api.push.model.Platform;
import cn.jpush.api.push.model.PushPayload;
import cn.jpush.api.push.model.audience.Audience;
import com.alibaba.fastjson.JSON;

import java.util.List;

/**
 * 使用别名:
 * 用于给某特定用户推送消息。别名，可以近似地被认为，是用户帐号里的昵称。
 * 使用标签:
 * 用于给某一群人推送消息。
 * 标签类似于博客里为文章打上 tag ，即为某资源分类。
 *
 */
public class JPushClientPC {

    /**
     * 发送所有的消息  全部人
     *
     * @param responseNoticeMessage
     * @return
     */
    public static PushPayload buildPushObject_all_message(ResponseNoticeMessage responseNoticeMessage) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())//设置接受的平台
                .setAudience(Audience.all())//Audience设置为all，说明采用广播方式推送，所有用户都可以接收到
                //.setNotification(Notification.alert(JSON.toJSONString(responseNoticeMessage)))
                .setMessage(Message.content(JSON.toJSONString(responseNoticeMessage)))  //内部消息不显示，类似web socket
                .build();
    }

    /**
     * 根据别名集合 推送
     *
     * @param userNames             别名List
     * @param responseNoticeMessage 消息
     * @return
     */
    public static PushPayload buildPushObject_all_alias_message(List<String> userNames,ResponseNoticeMessage responseNoticeMessage) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())//设置接受的平台
                .setAudience(Audience.alias(userNames))//
                //.setNotification(Notification.alert(JSON.toJSONString(responseNoticeMessage)))
                .setMessage(Message.content(JSON.toJSONString(responseNoticeMessage)))  //内部消息不显示，类似web socket
                .build();
    }

    /**
     * 根据别名 推送
     *
     * @param userName              别名
     * @param responseNoticeMessage 消息
     * @return
     */
    public static PushPayload buildPushObject_all_alias_message(String userName, ResponseNoticeMessage responseNoticeMessage) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())//设置接受的平台
                .setAudience(Audience.alias(userName))//
                //.setNotification(Notification.alert(JSON.toJSONString(responseNoticeMessage)))
                .setMessage(Message.content(JSON.toJSONString(responseNoticeMessage)))  //内部消息不显示，类似web socket
                .build();
    }

    /**
     * 根据标签集合推送
     *
     * @param tags                  标签List
     * @param responseNoticeMessage 消息
     * @return
     */
    public static PushPayload buildPushObject_all_tags_message(List<String> tags,ResponseNoticeMessage responseNoticeMessage) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())//设置接受的平台
                .setAudience(Audience.tag(tags))//
                //.setNotification(Notification.alert(JSON.toJSONString(responseNoticeMessage)))
                .setMessage(Message.content(JSON.toJSONString(responseNoticeMessage)))  //内部消息不显示，类似web socket
                .build();
    }

    /**
     * 根据标签推送
     *
     * @param tag                   标签
     * @param responseNoticeMessage 消息
     * @return
     */
    public static PushPayload buildPushObject_all_tag_message(String tag, ResponseNoticeMessage responseNoticeMessage) {
        return PushPayload.newBuilder()
                .setPlatform(Platform.all())//设置接受的平台
                .setAudience(Audience.tag(tag))//
                //.setNotification(Notification.alert(JSON.toJSONString(responseNoticeMessage)))
                .setMessage(Message.content(JSON.toJSONString(responseNoticeMessage)))  //内部消息不显示，类似web socket
                .build();
    }


}